package com.bjsxt.web.controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bjsxt.dao.CustomerDao;

public class UpdateCustomer extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		CustomerDao dao = new CustomerDao();
		java.util.Date birth;
		java.sql.Date sqlDate;
		boolean flag = false;
		try {
			birth = new SimpleDateFormat("yyyy-MM-dd").parse(req.getParameter("birth"));
			sqlDate = new java.sql.Date(birth.getTime());
			flag = dao.updateCustomer(Integer.parseInt(req.getParameter("id")), req.getParameter("userName"), Integer.parseInt(req.getParameter("gender")), sqlDate, req.getParameter("tel"));
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
		req.getRequestDispatcher("listCustomer.do").forward(req, resp);
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
}
